package com.hp.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.hp.ssm.entity.Role;
import com.hp.ssm.entity.User;
import com.hp.ssm.service.RoleService;
import com.hp.ssm.util.ResultJson;
import com.hp.ssm.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("RoleController")
public class RoleController {

    @Autowired
    RoleService roleService;

    @RequestMapping("selectAll")
    public String selectAll(User user,Integer page,Integer limit,HttpServletResponse response){
        System.out.println(user);
        List<User> list = roleService.selectAll(user,page,limit);
        PageInfo<User> userPageInfo = new PageInfo<User>(list);
        ResultJson success=ResultJson.success(userPageInfo);
        Utils.returnJson(success,response);
        return null;
    }
    @RequestMapping("selectAll1")
    public String selectAll1(Role role,Integer page,Integer limit,HttpServletResponse response){
        System.out.println(role);
        List<Role> list = roleService.selectAll1(role,page,limit);
        PageInfo<Role> userPageInfo = new PageInfo<Role>(list);
        ResultJson success=ResultJson.success(userPageInfo);
        Utils.returnJson(success,response);
        return null;
    }
    @RequestMapping("/promotion")
    @ResponseBody
    public String promotion(HttpServletResponse response,Integer aid){
        int i = roleService.promotion(aid);
        ResultJson success=ResultJson.success(i);
        Utils.returnJson(success,response);
        return null;
    }
    @RequestMapping("/demotion")
    @ResponseBody
    public String demotion(HttpServletResponse response,Integer aid){
        int i = roleService.demotion(aid);
        ResultJson success=ResultJson.success(i);
        Utils.returnJson(success,response);
        return null;
    }
    @RequestMapping("/getAuthority")
    @ResponseBody
    public String getAuthority(Integer rid,HttpServletResponse response){
        System.out.println(rid);
        List<Map> list = roleService.getAuthority(rid);
        ResultJson success=ResultJson.success(list);
        Utils.returnJson(success,response);
        return null;
    }
}
